package com.hot100.mid;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 二维数组的动态规划  每次只能向下或者向右移动一步
 * @date 2022/8/13 18:15
 */
public class Demo21 {
    public static void main(String[] args) {
       int[][] nums= {{1,2,3},{4,5,6}};
        minPathSum(nums);
    }


    public static int minPathSum(int[][] grid) {
         int hight= grid.length;
         int with=grid[0].length;
         int[][] dp=new int[hight][with];
          dp[0][0]=grid[0][0];
        for (int i = 0; i < hight; i++) {
            for (int j = 0; j <with ; j++) {
                if(i>0&j>0){
                    dp[i][j]=Math.min(dp[i-1][j],dp[i][j-1])+grid[i][j];
                }else if(i==0&j>0){
                    dp[i][j]=dp[i][j-1]+grid[i][j];
                }else if(i>0&j==0){
                    dp[i][j]=dp[i-1][j]+grid[i][j];
                }
            }
        }
        return dp[hight-1][with-1];
    }
}
